package com.windchime.blog.controller.admin;

import com.windchime.blog.entity.*;
import com.windchime.blog.entity.vo.TypeOrTagVo;
import com.windchime.blog.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * 后台页面跳转
 */
@Controller
public class AdminPageController {

    @Autowired
    private UserService userService;

    @Autowired
    private TypeService typeService;

    @Autowired
    private TagService tagService;

    @Autowired
    private FriendService friendService;

    @Autowired
    private BlogService blogService;

    @Autowired
    private ResourceTypeService resourceTypeService;

    @Autowired
    private ResourceService resourceService;

    @Autowired
    private CommentService commentService;

    /**
     * 到登录页
     * @return login
     */
    @GetMapping("/admin")
    public String admin() {
        return "admin/page/login";
    }

    /**
     * 到修改管理员密码页面
     * @return password-edit
     */
    @GetMapping("/admin/password-edit")
    public String passwordEdit() {
        return "admin/page/admin-password-edit";
    }

    /**
     * 到index首页
     * @return index
     */
    @GetMapping("/admin/index")
    public String adminIndex() {
        return "admin/index";
    }

    /**
     * 到欢迎页
     * @return welcome
     */
    @GetMapping("/admin/welcome")
    public String welcome() {
        return "admin/page/welcome";
    }

    /**
     * 到用户操作
     * @return user-list
     */
    @GetMapping("/admin/user/user-list")
    public String userList() {
        return "admin/page/user/user-list";
    }
    @GetMapping("/admin/user/user-add")
    public String userAdd() {
        return "admin/page/user/user-add";
    }

    /**
     * 从页面获取到ID
     * @param id 用户ID
     * @return user-edit
     */
    @GetMapping("/admin/user/user-edit/{id}")
    public String userEdit(@PathVariable Long id, Model model) {
        User user = userService.getById(id);
        model.addAttribute("user", user);
        return "admin/page/user/user-edit";
    }

    @GetMapping("/admin/blog/blog-list")
    public String blogList() {
        return "admin/page/blog/blog-list";
    }

    @GetMapping("/admin/blog/blog-add")
    public String blogAdd() {
        return "admin/page/blog/blog-add";
    }

    /**
     * 从页面获取ID
     * @param id 博客ID
     * @return blog-edit
     */
    @GetMapping("/admin/blog/blog-edit/{id}")
    public String blogEdit(@PathVariable Long id, Model model) {
        Blog blog = blogService.getById(id);
        model.addAttribute("blog", blog);
        return "admin/page/blog/blog-edit";
    }

    @GetMapping("/admin/type/type-list")
    public String typeList() {
        return "admin/page/type/type-list";
    }
    @GetMapping("/admin/type/type-add")
    public String typeAdd() {
        return "admin/page/type/type-add";
    }

    /**
     * 从页面获取到ID
     * @param id 分类ID
     * @return type-edit
     */
    @GetMapping("/admin/type/type-edit/{id}")
    public String typeEdit(@PathVariable Long id, Model model) {
        Type type = typeService.getById(id);
        model.addAttribute("type", type);
        return "admin/page/type/type-edit";
    }

    @GetMapping("/admin/tag/tag-list")
    public String tagList() {
        return "admin/page/tag/tag-list";
    }
    @GetMapping("/admin/tag/tag-add")
    public String tagAdd() {
        return "admin/page/tag/tag-add";
    }

    /**
     * 从页面获取到ID
     * @param id 标签ID
     * @return tag-edit
     */
    @GetMapping("/admin/tag/tag-edit/{id}")
    public String tagEdit(@PathVariable Long id, Model model) {
        Tag tag = tagService.getById(id);
        model.addAttribute("tag", tag);
        return "admin/page/tag/tag-edit";
    }

    @GetMapping("/admin/friend/friend-list")
    public String friendList() {
        return "admin/page/friend/friend-list";
    }
    @GetMapping("/admin/friend/friend-add")
    public String friendAdd() {
        return "admin/page/friend/friend-add";
    }

    /**
     * 从页面获取到ID
     * @param id 友链ID
     * @return friend-edit
     */
    @GetMapping("/admin/friend/friend-edit/{id}")
    public String friendEdit(@PathVariable Long id, Model model) {
        Friend friend = friendService.getById(id);
        model.addAttribute("friend", friend);
        return "admin/page/friend/friend-edit";
    }

    @GetMapping("/admin/comment/comment-list")
    public String commentList() {
        return "admin/page/comment/comment-list";
    }
    @GetMapping("/admin/comment/comment-add")
    public String commentAdd() {
        return "admin/page/comment/comment-add";
    }

    /**
     * 传值给评论回复内容
     * @param id 评论ID
     * @param model 传值
     * @return reply
     */
    @GetMapping("/admin/comment/comment-reply/{id}")
    public String commentReply(@PathVariable Long id, Model model) {
        model.addAttribute("comment", commentService.getById(id));
        return "admin/page/comment/comment-reply";
    }

    @GetMapping("/admin/resource-type/resource-type-list")
    public String resourceTypeList() {
        return "admin/page/resource/resource-type-list";
    }
    @GetMapping("/admin/resource-type/resource-type-add")
    public String resourceTypeAdd() {
        return "admin/page/resource/resource-type-add";
    }

    /**
     * 从页面获取到ID
     * @param id 资源分类ID
     * @return resource-type-edit
     */
    @GetMapping("/admin/resource-type/resource-type-edit/{id}")
    public String resourceTypeEdit(Model model, @PathVariable Long id) {
        ResourceType resourceType = resourceTypeService.getById(id);
        model.addAttribute("resourceType", resourceType);
        return "admin/page/resource/resource-type-edit";
    }

    @GetMapping("/admin/resource/resource-list")
    public String resourceList() {
        return "admin/page/resource/resource-list";
    }
    @GetMapping("/admin/resource/resource-add")
    public String resourceAdd() {
        return "admin/page/resource/resource-add";
    }

    @GetMapping("/admin/resource/resource-edit/{id}")
    public String resourceEdit(Model model, @PathVariable Long id) {
        model.addAttribute("resource", resourceService.getById(id));
        return "admin/page/resource/resource-edit";
    }
}
